﻿using System;
using System.Configuration;
using System.Data;
using System.Security.Cryptography;
using System.Text;
using System.IO;
using System.Web;

namespace BySoft.Web.Utility
{
    public class EncodeHelper
    {
        /// <summary>
        /// MD5加密
        /// </summary>
        /// <param name="strOriginal"></param>
        /// <returns></returns>
        public static string MD5Encode(string strOriginal)
        {
            byte[] byteInput = UTF8Encoding.UTF8.GetBytes(strOriginal);
            MD5CryptoServiceProvider objMD5 = new MD5CryptoServiceProvider();
            byte[] byteOutput = objMD5.ComputeHash(byteInput);
            return BitConverter.ToString(byteOutput).Replace("-", "");
        }

        /// <summary>
        /// 使用utf-8编码进行Encode解码
        /// </summary>
        /// <param name="str">待编码的字串</param>
        /// <returns>Encode编码后的字串</returns>
        public static string UrlEncode(string str)
        {
            return HttpUtility.UrlEncode(str, System.Text.Encoding.GetEncoding("utf-8"));
        }

        /// <summary>
        /// 使用utf-8编码进行Decode解码
        /// </summary>
        /// <param name="str">已编码的字串</param>
        /// <returns>解码后的字串</returns>
        public static string UrlDecode(string str)
        {
            return HttpUtility.UrlDecode(str, System.Text.Encoding.GetEncoding("utf-8"));
        }


    }
}
